package LeetCode.Solution_02;

public class Solution_02 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode pre, cur;
        pre = cur = new ListNode();
        boolean jw = false;
        int cValue; // tip 声明在循环体外面~
        while ((l1 != null && l2 != null) || jw) {
            cValue = jw ? 1 : 0;

            if (l1 != null) {
                cValue += l1.val;
                l1 = l1.next;
            }
            if (l2 != null) {
                cValue += l2.val;
                l2 = l2.next;
            }

            cur.next = new ListNode(cValue % 10);
            cur = cur.next;

            jw = cValue >= 10;
            if (!jw && l1 == null) cur.next = l2;
            if (!jw && l2 == null) cur.next = l1;
        }
        return pre.next;
    }


}
